package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.api.contant.model.dto.CourseBaseDTO;
import com.xuecheng.api.contant.model.dto.TeachplanDTO;
import com.xuecheng.api.media.model.TeachplanMediaDTO;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.enums.common.CommonEnum;
import com.xuecheng.common.enums.content.CourseAuditEnum;
import com.xuecheng.common.enums.content.CourseModeEnum;
import com.xuecheng.common.enums.content.TeachPlanEnum;
import com.xuecheng.common.exception.ExceptionCast;
import com.xuecheng.common.util.StringUtil;
import com.xuecheng.content.common.constant.ContentErrorCode;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.convert.TeachplanMediaConvert;
import com.xuecheng.content.entity.CourseBase;
import com.xuecheng.content.entity.Teachplan;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.entity.ext.TeachplanNode;
import com.xuecheng.content.mapper.TeachplanMapper;
import com.xuecheng.content.service.CourseBaseService;
import com.xuecheng.content.service.TeachplanMediaService;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程计划 服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class TeachplanServiceImpl extends ServiceImpl<TeachplanMapper, Teachplan> implements TeachplanService {

    @Autowired
    private CourseBaseService courseBaseService;

    @Autowired
    private TeachplanMediaService teachplanMediaService;

    @Autowired
    private TeachplanMapper teachplanMapper;

    /*
        * 业务分析：
        *   1.判断关键数据
        *       teachplanId、mediaId,companyId
        *   2.判断业务数据
        *       课程的计划
        *           判断是否是第三级
        *           判断课程类型是否录播（课程基本信息中获得并判断）
        *           判断课程计划是否存在：teachplanId、courseId
        *
        *       课程基本信息
        *           判断是否存在或是否是同一家机构
        *           判断是否删除
        *           判断审核状态：未提交、审核未通过
        *
        *       媒资信息
        *           判断媒资信息是否存在
        *           判断是否是同一家机构
        * */
    @Transactional
    @Override
    public TeachplanMediaDTO associateMedia(TeachplanMediaDTO dto, Long companyId) {
        // 1、判断关键数据
        if (ObjectUtils.isEmpty(companyId) || ObjectUtils.isEmpty(dto.getTeachplanId()) || ObjectUtils.isEmpty(dto.getMediaId())) {
            ExceptionCast.cast(ContentErrorCode.E_120017);
        }
        // 2、判断业务数据        *       课程的计划
        //        *           判断是否是第三级
        //        *           判断课程类型是否录播（课程基本信息中获得并判断）
        //        *           判断课程计划是否存在：teachplanId、courseId
        Teachplan teachplan = this.getById(dto.getTeachplanId());
        // teachplan
        if (ObjectUtils.isEmpty(teachplan)) {
            ExceptionCast.cast(ContentErrorCode.E_120402);
        }
        // 判断是否是三级
        if (!teachplan.getGrade().equals(TeachPlanEnum.THIRD_LEVEL)) {
            ExceptionCast.cast(ContentErrorCode.E_120410);
        }
        // 课程信息id 课程计划id
        if (ObjectUtils.isEmpty(teachplan.getCourseId()) || ObjectUtils.isEmpty(teachplan.getId())) {
            ExceptionCast.cast(ContentErrorCode.E_120402);
        }
        // 判断课程类型是否录播
/*        CourseBase courseBase = courseBaseService.getById(teachplan.getCourseId());
        if (!courseBase.getTeachmode().equals(CourseModeEnum.COURSE_MODE_RECORD_STATUS.getCode())) {
            ExceptionCast.cast(ContentErrorCode.E_120026);
        }

        if (courseBase.getStatus().equals(CommonEnum.DELETE_FLAG.getCodeInt())){
            ExceptionCast.cast(ContentErrorCode.E_120013);
        }
        if (courseBase.getAuditStatus().equals(CourseAuditEnum.AUDIT_UNPAST_STATUS.getCode()) ||
        courseBase.getAuditStatus().equals(CourseAuditEnum.AUDIT_DISPAST_STATUS.getCode())
        ){
            ExceptionCast.cast(ContentErrorCode.E_120015);
        }
        if (!courseBase.getCompanyId().equals(companyId)){
            ExceptionCast.cast(ContentErrorCode.E_120020);
        }*/

        TeachplanMedia teachplanMedia = TeachplanMediaConvert.INSTANCE.dto2entity(dto);
        if (!teachplanMedia.getTeachplanId().equals(dto.getTeachplanId())){
            boolean result = teachplanMediaService.save(teachplanMedia);
            if (!result){
                ExceptionCast.cast(ContentErrorCode.E_120407);
            }
        }else {
            teachplanMedia.setMediaId(dto.getMediaId());
            teachplanMedia.setMediaFilename(dto.getMediaFilename());
            boolean flag = teachplanMediaService.updateById(teachplanMedia);
            if (!flag){
                ExceptionCast.cast(ContentErrorCode.E_120411);
            }

        }
        TeachplanMediaDTO teachplanMediaDTO = TeachplanMediaConvert.INSTANCE.entity2dto(teachplanMedia);
        return teachplanMediaDTO;
    }

    /**
     * 根据课程Id查询课程计划（树形结构）
     *
     * @param courseId  课程基本信息id
     * @param companyId 机构id
     * @return TeachplanDTO 返回封装DTO
     */
/*    @Override
    public TeachplanDTO queryTreeNodesByCourseId(Long courseId, Long companyId) {
        // 1、关键数据判断，业务判断
        //1.判断关键
        //courseId  companyId
        if (ObjectUtils.isEmpty(courseId)) {
            ExceptionCast.cast(ContentErrorCode.E_120019);
        }
        if (ObjectUtils.isEmpty(companyId)) {
            ExceptionCast.cast(ContentErrorCode.E_120019);
        }
        //    课程基础信息
        //        判断是否存在
        //        判断是否是同一家教学机构
        //        判断是否删除
        CourseBase courseBase = courseBaseService.getById(courseId);
        if (ObjectUtils.isEmpty(courseBase)) {
            ExceptionCast.cast(ContentErrorCode.E_120013);
        }
        if (!companyId.equals(courseBase.getCompanyId())) {
            ExceptionCast.cast(ContentErrorCode.E_120020);
        }
        if (!courseBase.getStatus().equals(CommonEnum.USING_FLAG.getCodeInt())) {
            ExceptionCast.cast(ContentErrorCode.E_120024);
        }

        // 2、根据courseId查询一门课程下的所有课程计划

        List<TeachplanNode> nodes = teachplanMapper.selectTreeNodesByCourseId(courseId);
        TeachplanDTO teachplanDTO =null;
        // 3、判断当前子级数据集合是否为空
        if (!CollectionUtils.isEmpty(nodes)){
            // 4、获得一级课程计划数据并删除
            TeachplanNode firstNode = nodes.remove(0);
            // 5、使用java递归方式来生成树形结构
            gengerateTreeNode(firstNode,nodes);
            //获取子级数据集合
            List<TeachplanNode> childrenNodes = firstNode.getChildrenNodes();
            // 将子级数据集合转换为dtos
            List<TeachplanDTO> teachplanDTOS = TeachplanConvert.INSTANCE.nodes2dtos(childrenNodes);
            // 将父级node转换为dto
            teachplanDTO = TeachplanConvert.INSTANCE.node2dto(firstNode);
            // 赋值课程计划子级树形结构集合
            teachplanDTO.setTeachPlanTreeNodes(teachplanDTOS);
        }else {

            teachplanDTO=new TeachplanDTO();
        }
        // 返回dto
        return teachplanDTO;
    }

    // 使用java递归方式来生成树形结构
    private void gengerateTreeNode(TeachplanNode parentNode, List<TeachplanNode> nodes) {
        if (ObjectUtils.isEmpty(parentNode.getChildrenNodes())) {
            parentNode.setChildrenNodes(new ArrayList<TeachplanNode>());
        }
        for (TeachplanNode node : nodes) {
            // 将父级数据和子级数据进行关联
            // parentNode.id = node.parentId
            if (ObjectUtils.nullSafeEquals(parentNode.getId(), node.getParentid())) {

                parentNode.getChildrenNodes().add(node);

                // 递归的出口是：如果是三级课程计划不进行递归
                if (!(TeachPlanEnum.THIRD_LEVEL.equals(node.getGrade()))) {
                    gengerateTreeNode(node, nodes);
                }
            }
        }
    }*/
    @Override
    public TeachplanDTO queryTreeNodesByCourseId(Long courseId, Long companyId) {
        //1.判断关键数据
        //    courseId companyId
        if (ObjectUtils.isEmpty(courseId) ||
                ObjectUtils.isEmpty(companyId)
        ) {
            ExceptionCast.cast(ContentErrorCode.E_120013);
        }

        //2.判断业务数据
        //    课程基础信息
        //        判断是否存在
        //        判断是否是同一家教学机构
        //        判断是否删除
        CourseBase courseBase = courseBaseService.getById(courseId);
        if (ObjectUtils.isEmpty(courseBase)) {
            ExceptionCast.cast(ContentErrorCode.E_120013);
        }
        if (!companyId.equals(courseBase.getCompanyId())) {
            ExceptionCast.cast(ContentErrorCode.E_120020);
        }
        if (!courseBase.getStatus().equals(CommonEnum.USING_FLAG.getCodeInt())) {
            ExceptionCast.cast(ContentErrorCode.E_120024);
        }
        //3.根据Courseid查询课程计划数据
        List<TeachplanNode> teachplanNodes = teachplanMapper.selectTreeNodesByCourseId(courseId);
        TeachplanDTO teachplanDTO = null;
        if (ObjectUtils.isEmpty(teachplanNodes)) {
            teachplanDTO = new TeachplanDTO();
        } else {
            TeachplanNode root = teachplanNodes.remove(0);
            //4.通过java的递归生成课程计划树形结构
            generateTreeNodes(root, teachplanNodes);
            //5.将数据转为dto并返回
            List<TeachplanNode> childrenNodes = root.getChildrenNodes();
            List<TeachplanDTO> teachplanDTOS = TeachplanConvert.INSTANCE.nodes2dtos(childrenNodes);
            teachplanDTO = TeachplanConvert.INSTANCE.node2dto(root);
            teachplanDTO.setTeachPlanTreeNodes(teachplanDTOS);
        }
        return teachplanDTO;
    }

    private TeachplanNode generateTreeNodes(TeachplanNode root, List<TeachplanNode> teachplanNodes) {
        if (CollectionUtils.isEmpty(root.getChildrenNodes())) {
            root.setChildrenNodes(new ArrayList<TeachplanNode>());
        }
        for (TeachplanNode node : teachplanNodes) {
            if (ObjectUtils.nullSafeEquals(root.getId(), node.getParentid())) {
                root.getChildrenNodes().add(node);
                if (!(node.getGrade().equals(TeachPlanEnum.THIRD_LEVEL))) {
                    generateTreeNodes(node, teachplanNodes);
                }
            }
        }
        return root;
    }

    /**
     * 根据课程计划Id删除课程计划信息
     *
     * @param teachPlanId {@link Long} 课程计划Id
     * @param companyId   {@link Long} 公司Id
     */
    @Override
    @Transactional
    public void removeTeachPlan(Long teachPlanId, Long companyId) {
        //1.判断关键
        //teachplanId  companyId
        if (ObjectUtils.isEmpty(teachPlanId)) {
            ExceptionCast.cast(ContentErrorCode.E_120402);
        }
        if (ObjectUtils.isEmpty(companyId)) {
            ExceptionCast.cast(ContentErrorCode.E_120019);
        }
        Teachplan teachplan = this.getById(teachPlanId);
        if (ObjectUtils.isEmpty(teachplan)) {
            ExceptionCast.cast(ContentErrorCode.E_120402);
        }
        //2.判断业务数据
        //        课程基础信息
        //        判断是否存在、判断是否是同一家教学机构、判断是否删除、判断审核状态（未提交、审核未通过）
        Long courseId = teachplan.getCourseId();
        CourseBaseDTO courseBaseDTO = courseBaseService.getByCourseId(courseId, companyId);
        if (ObjectUtils.isEmpty(courseBaseDTO)) {
            ExceptionCast.cast(ContentErrorCode.E_120013);
        }

        // 2、课程计划业务判断
        // 如果是一级不可删除
        Integer grade = teachplan.getGrade();
        if (grade.equals(TeachPlanEnum.FIRST_LEVEL)) {
            throw new RuntimeException("当前是一级不可删！");
        }
        // 如果是二级
        LambdaQueryWrapper<Teachplan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Teachplan::getParentid, teachplan.getId());
        int count = this.count(wrapper);
        if (count > 0) {
            throw new RuntimeException("当前二级不让删除，关联着子级");
        }
        // 如果是三级
        if (grade.equals(TeachPlanEnum.THIRD_LEVEL)) {
            //        判断课程计划是否有关联数据（查询TeachplanMedia表数据）
            if (courseBaseDTO.getTeachmode().equals(CourseModeEnum.COURSE_MODE_RECORD_STATUS.getCode())) {
                LambdaQueryWrapper<TeachplanMedia> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(TeachplanMedia::getTeachplanId, teachplan.getId());
                int num = teachplanMediaService.count(queryWrapper);
                if (num > 0) {
                    ExceptionCast.cast(ContentErrorCode.E_120411);
                }
            }
        }
        boolean result = this.removeById(teachPlanId);
        //        4.判断操作结果
        if (!result) {
            ExceptionCast.cast(ContentErrorCode.E_120021);
        }
    }

    /**
     * 新增或修改课程计划
     *
     * @param dto 课程计划封装类型数据
     * @return teachplanDTO 课程计划封装类型返回数据
     */
    @Override
    @Transactional // 开启事务
    public TeachplanDTO createModifyTeachplan(TeachplanDTO dto, Long companyId) {
        // 1、判断业务操作
        Long teachPlanId = dto.getTeachPlanId();
        TeachplanDTO resultDTO = null;
        // 2、如果没有 teachplanid 就是新增操作，有就是修改操作
        if (ObjectUtils.isEmpty(teachPlanId)) {
            resultDTO = createTeachplan(dto, companyId);
        } else {
            resultDTO = modifyTeachplan(dto, companyId);
        }
        // 3、返回dto数据
        return resultDTO;
    }

    // todo:新增课程计划信息
    private TeachplanDTO createTeachplan(TeachplanDTO dto, Long companyId) {
        //1.判断关键数据
        //     pname  courseId  companyId
        // 2.判断业务数据
        //     课程基础信息
        //         判断是否存在
        //         判断是否删除
        //         判断是否是同一家机构
        //         判断审核状态：未提交和审核未通过
        CourseBaseDTO courseBase = this.getCourseBaseDTO(dto, companyId);
        // 3、给数据赋值
        // 获取父级数据
        Teachplan parentNode = getParentDate(dto, courseBase);
        // 赋值等级和父类id
        dto.setGrade(parentNode.getGrade() + 1);
        dto.setParentid(parentNode.getId());
        // 根据父类id条件 查询
        LambdaQueryWrapper<Teachplan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Teachplan::getParentid, parentNode.getId());
        int count = this.count(wrapper);
        // 赋值orderBy
        dto.setOrderby(count + 1);
        //    关联数据：父级id值
        //4.将dto数据转为po并保存到数据中
        Teachplan teachplan = TeachplanConvert.INSTANCE.dto2entity(dto);
        if (!ObjectUtils.isEmpty(dto.getTeachplanMedia())) {
            teachplan.setMediaType(dto.getTeachplanMedia());
        }
        boolean teachplanFlag = this.save(teachplan);
        if (!teachplanFlag) {
            ExceptionCast.cast(ContentErrorCode.E_120407);
        }
        // 调用方法查询课程计划信息
        Teachplan po = this.getById(teachplan.getId());
        // 将po转成dto数据
        TeachplanDTO teachplanDTO = TeachplanConvert.INSTANCE.entity2dto(po);
        // 返回dto数据
        return teachplanDTO;
    }

    // 关键数据判断和业务判断
    private CourseBaseDTO getCourseBaseDTO(TeachplanDTO dto, Long companyId) {
        // 1、关键数据判断
        if (StringUtil.isBlank(dto.getPname()) ||
                ObjectUtils.isEmpty(dto.getCourseId()) ||
                ObjectUtils.isEmpty(companyId)) {
            ExceptionCast.cast(CommonErrorCode.E_100101);
        }
        // 2、业务数据判断
        // 获取课程基础信息
        CourseBaseDTO courseBase = courseBaseService.getByCourseId(dto.getCourseId(), companyId);
        // 课程基础信息是否被删除
        if (courseBase.getStatus().equals(CommonEnum.DELETE_FLAG.getCodeInt())) {
            ExceptionCast.cast(ContentErrorCode.E_120021);
        }
        // 课程基本信息是否存在
        if (ObjectUtils.isEmpty(courseBase)) {
            ExceptionCast.cast(ContentErrorCode.E_120013);
        }
        // 判断审核状态
        if (courseBase.getAuditStatus().equals(CourseAuditEnum.AUDIT_COMMIT_STATUS.getCode())
                || courseBase.getAuditStatus().equals(CourseAuditEnum.AUDIT_PASTED_STATUS.getCode())
                || courseBase.getAuditStatus().equals(CourseAuditEnum.AUDIT_PUBLISHED_STATUS.getCode())
        ) {
            ExceptionCast.cast(ContentErrorCode.E_120015);
        }
        return courseBase;
    }

    /*
    获得二级和三级课程计划父级数据（一级和二级）
    1.课程计划的一级（根级）
    - 数据来源：课程基础信息（CourseBase）
    - 创建时机：在第一次添加二级数据时自动生成
    - 注意事项：一级父级（根级）父级 ID 值为 0

    2.课程计划的二级和三级节点
    - 数据来源：教育机构人员在页面填写的数据
    - 创建时机：教育机构人员提交课程计划数据
    - 注意事项：添加时要校验父级菜单是否存在
      - 二级在添加时
        - 父级不存在（一级）：自动创建并获得获得父级Id值
        - 父级存在（一级）：获得父级Id值
      - 三级在添加时
        - 父级不存在（二级）：抛出异常
        - 父级存在（二级）：获得父级Id值
* */
    // 获取课程计划父级
/*    private Teachplan getParentDate(TeachplanDTO dto, CourseBaseDTO courseBase) {
        // 获取课程计划父类id
        Long parentid = dto.getParentid();
        if (ObjectUtils.isEmpty(parentid)) {
            //获得二级父级数据
            LambdaQueryWrapper<Teachplan> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Teachplan::getCourseId, courseBase.getCourseBaseId());
            wrapper.eq(Teachplan::getParentid, TeachPlanEnum.FIRST_PARENTID_FLAG);
            //调用方法获取二级课程计划信息
            Teachplan parentNode = this.getOne(wrapper);

            if (ObjectUtils.isEmpty(parentNode)) {
                // 在后端自动创建课程计划一级数据
                parentNode = new Teachplan();
                parentNode.setPname(courseBase.getName());
                parentNode.setParentid(new Long(TeachPlanEnum.FIRST_PARENTID_FLAG));
                parentNode.setGrade(TeachPlanEnum.FIRST_LEVEL);
                parentNode.setOrderby(TeachPlanEnum.FIRST_LEVEL);
                parentNode.setCourseId(courseBase.getCourseBaseId());

                boolean flag = this.save(parentNode);
                if (!flag) {
                    ExceptionCast.cast(ContentErrorCode.E_120407);
                }
            }
            return parentNode;
        }
        else {
            // 获取三级父级数据
            LambdaQueryWrapper<Teachplan> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Teachplan::getId, parentid);
            queryWrapper.eq(Teachplan::getCourseId, courseBase.getCourseBaseId());

            Teachplan parentNode = this.getOne(queryWrapper);
            if (ObjectUtils.isEmpty(parentNode)) {
                ExceptionCast.cast(ContentErrorCode.E_120408);
            }
            // 返回三级数据
            return parentNode;
        }
    }*/
    private Teachplan getParentDate(TeachplanDTO teachplanDTO, CourseBaseDTO courseBase) {
        // 判断新增数据是否是三级还是二级
        // 根据parentid来判断
        //   如果有：三级课程计划   -->父级（二级）
        //   如果没有：二级级课程计划 -->父级（一级）
        Long parentid = teachplanDTO.getParentid();
        if (ObjectUtils.isEmpty(parentid)) {
            //获取二级课程计划的父级
            // 根据courseId和parentid=0来查找一个课程上一级课程计划数据
            LambdaQueryWrapper<Teachplan> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Teachplan::getCourseId, courseBase.getCourseBaseId());
            queryWrapper.eq(Teachplan::getParentid, TeachPlanEnum.FIRST_PARENTID_FLAG);
            Teachplan parentNode = this.getOne(queryWrapper);
            if (ObjectUtils.isEmpty(parentNode)) {
                // 在后端自动创建课程计划一级数据
                parentNode = new Teachplan();
                parentNode.setPname(courseBase.getName());
                parentNode.setParentid(new Long(TeachPlanEnum.FIRST_PARENTID_FLAG));
                parentNode.setGrade(TeachPlanEnum.FIRST_LEVEL);
                parentNode.setOrderby(TeachPlanEnum.FIRST_LEVEL);
                parentNode.setCourseId(courseBase.getCourseBaseId());
                boolean result = this.save(parentNode);
                if (!result) {
                    ExceptionCast.cast(ContentErrorCode.E_120013);
                }
            }
            return parentNode;
        } else {
            //获取三级课程计划的父级
            LambdaQueryWrapper<Teachplan> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Teachplan::getId, parentid);
            queryWrapper.eq(Teachplan::getCourseId, courseBase.getCourseBaseId());
            Teachplan parentNode = this.getOne(queryWrapper);
            if (ObjectUtils.isEmpty(parentNode)) {
                ExceptionCast.cast(ContentErrorCode.E_120408);
            }
            return parentNode;
        }
    }

    // todo:修改课程计划信息
    private TeachplanDTO modifyTeachplan(TeachplanDTO dto, Long companyId) {
        // 1、调用方法
        getCourseBaseDTO(dto, companyId);
        // 2、判断课程计划信息是否存在，判断课程计划得等级
        LambdaQueryWrapper<Teachplan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Teachplan::getId, dto.getTeachPlanId());
        Teachplan teachplan = this.getOne(wrapper);
        if (ObjectUtils.isEmpty(teachplan)) {
            ExceptionCast.cast(ContentErrorCode.E_120402);
        }
        // 判断课程计划等级
        Integer grade = teachplan.getGrade();
        if (!grade.equals(TeachPlanEnum.SECEND_LEVEL) && !grade.equals(TeachPlanEnum.THIRD_LEVEL)) {
            ExceptionCast.cast(ContentErrorCode.E_120408);
        }
        // 3、修改课程计划信息
        LambdaUpdateWrapper<Teachplan> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Teachplan::getPname, dto.getPname());
        updateWrapper.set(Teachplan::getIsPreview, dto.getIsPreview());
        updateWrapper.set(Teachplan::getChangeDate, LocalDateTime.now());
        updateWrapper.eq(Teachplan::getId, dto.getTeachPlanId());
        // todo
        if (!ObjectUtils.isEmpty(dto.getTeachplanMedia())) {
            updateWrapper.set(Teachplan::getMediaType, dto.getTeachPlanId());
        }
        // 4、调用方法并判断修改后的结果
        boolean flag = this.update(updateWrapper);

        if (!flag) {
            ExceptionCast.cast(ContentErrorCode.E_120407);
        }
        // 5、返回dto数据
        Teachplan po = this.getById(teachplan.getId());
        TeachplanDTO teachplanDTO = TeachplanConvert.INSTANCE.entity2dto(po);
        return teachplanDTO;
    }
}
